function [input_name,output_label] = run_labeling(information) % dir_label where data is, dir_model after you train the model
% dir_label = 'C:/Documents and Settings/labadmin/Desktop/MUSL_Corey/Recognitioncode/Testing';
% dir_model = 'C:/Documents and Settings/labadmin/Desktop/MUSL_Corey/Recognitioncode/HMM15';
% ============= Script file ==========

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%testing%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%addpath('C:\Documents and Settings\labadmin\Desktop\MUSL_Corey\Standalone Modified\HTK');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:length(information)
    word = information{i};
    information(i) = cellstr(strrep(word,'\','/'));
end

dir_model = information{1};
dir_label = information{2};
config = information{3};
wdnet = information{4};
gram = information{5};
dict = information{6};
model = information{7};

global main_dir;

files_label=dir(dir_label);
if (exist([main_dir '/Data/MFC_label'],'dir')~=7)
        mkdir([main_dir '/Data'], ['MFC_label']);
end

fid=fopen('Data/codewords_label.scp','w');

for j=1:length(files_label)-2
    fprintf(fid,['"' dir_label '/' files_label(j+2).name '" \t']);
    fprintf(fid,['MFC_label/' files_label(j+2).name(1:end-4) '.mfc \n']);
end

fclose(fid);

% ===== Label files =========

fid=fopen('Data/label_label.mlf','w');
fprintf(fid,'#!MLF!#\n');

for j=1:length(files_label)-2
    fprintf(fid,['"*/'  files_label(j+2).name(1:end-4) '.lab" \n']);
    fprintf(fid,'sil \n');
    fprintf(fid,[ files_label(j+2).name '\n']);
    fprintf(fid,'sil \n');
    fprintf(fid,'.\n');
end
fclose(fid);

% % ====== Data prepare  bathfile============

fid=fopen('Data/dataprep_label.bat','w');
fprintf(fid, ['HParse "' gram '" "' wdnet '" \n']);
fprintf(fid, ['HCopy -C "' config '" -S codewords_label.scp \n']);
fclose(fid);

%  ============Script file for testing===========

fid=fopen('Data/test_label.scp','w');
for j=1:length(files_label)-2
    fprintf(fid,['MFC_label/' files_label(j+2).name(1:end-4) '.mfc \n']);
end
fclose(fid);

fid=fopen('Data/decoding_label.bat','w');
fprintf(fid, ['HVite -H "' dir_model '" -S test_label.scp -w "' wdnet '" -l' ' * ' '-i result_label.mlf -p 0.0 -s 0.0 "' dict '" "' model '"']);
fclose(fid);
cd('Data')
dos('dataprep_label.bat');
dos('decoding_label.bat');
cd('..')
% ======== Read in result =============

fid = fopen('Data/result_label.mlf');
x=textscan(fid,'%s');
fclose(fid);
j=1;
for i=0:(length(x{1})-1)/6-1
    input_name{j}=x{1}{2+6*i}(1:end-5);
    output_label{j}=x{1}{5+6*i};
    j=j+1;  
end